var express = require('express');
var loginRouter = express.Router();
var db = require('../config/sq')

/* 登录. */
loginRouter.post('/', async(req, res, next)=> {
    console.log('req.body',req.body);
    const val=req.body;
    const userName=val.userName;
    const passWord=val.passWord;
    const [rows,fields]=await db.query(`select * from users where name = ? and password = ? `,[userName,passWord])
    console.log('rows',rows)
    if(rows.length){
        res.cookie('token', '122', { maxAge: 10000*6 });
        res.send({data:true,msg:'成功',code:'0',token:new Date().getTime()})
    }else{
        res.send({data:false,msg:'失败',code:'1',token:null})
    }
});
loginRouter.get('/', async(req, res, next)=> {
    console.log('req.body',req.body);
    const val=req.body;
    const userName=val.userName;
    const passWord=val.passWord;
    const [rows,fields]=await db.query(`select * from users `,)
    console.log('rows',rows)
    if(rows.length){
        res.cookie('token', '122', { maxAge: 10000*6 });
        res.send({data:true,msg:'成功',code:'0',token:new Date().getTime()})
    }else{
        res.send({data:false,msg:'失败',code:'1',token:null})
    }
});

module.exports = loginRouter;
